
import json
from ronglian_sms_sdk import SmsSDK

accId = '2c94811c8cd4da0a018f3549b8d279ac'
accToken = '9ac15f4290e44155ad7cf092fa6308cb'
appId = '2c94811c8cd4da0a018f3549ba6579b3'



# 发送短信验证码
class CCP:
    # 创建单列模式
    _instance = None
    # 使用new静态方法 创建时值分配一个内存空间 , 避免内存的浪费
    def __new__(cls, *args, **kwargs):
        if cls._instance is None:
            cls._instance = super().__new__(cls, *args, **kwargs)
        return cls._instance

    def send_message(self,mobile,datas):
        sdk = SmsSDK(accId, accToken, appId)
        tid = '1'
        resp = sdk.sendMessage(tid, mobile, datas)
        resp = json.loads(resp)

        # 判断短信验证码是否发送成功
        if resp["statusCode"] == "000000":
            # 短信验证码发送成功
            return 0
        else:
            return -1

send_code = CCP()